home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CICA Windows Explosion!
/
The CICA Windows Explosion! - Disc 2.iso
/
programr
/
what.zip
/
DLLDEMO.C_
/
DLLDEMO.bin
Wrap
Text File
|
1992-07-16
|
10KB
|
371 lines
/*****************************************************************************
*
* dlldemo.c
*
******************************************************************************
* (C) Copyright Microsoft Corp. 1991. All rights reserved. *
* *
* You have a royalty-free right to use, modify, reproduce and *
* distribute the Sample Files (and/or any modified version) in *
* any way you find useful, provided that you agree that *
* Microsoft has no warranty obligations or liability for any *
* Sample Application Files which are modified. *
******************************************************************************
*
* Test Notes:
* CodeView.
* 1) Make a progman item with the following instruction:
* "cvw /l dlldemo.dll c:\windows\winhelp.exe dlldemo.hlp"
* (assuming you installed windows in the "c:\windows" directory).
* 3) during startup, it will say, debug information not found. Ignore
* this message- it is because it can't find debug info for
* winhelp internal routines which you don't need.
* after startup, you will be in cvw window. Pulldown File:Load Module.
* 4) select libmain.c
* 5) page down and set a breakpoint in LibMain() [click on a line]
* 6) press F5 or click on the run button to Go. Winhelp will load,
* and then break into Codeview at the LibMain() function.
*
*****************************************************************************/
#include <windows.h>
#include "dll.h"
#include "dlldemo.h"
#define PUBLIC extern /* Public label. */
#define PRIVATE static /* Private label. */
#define DEFAULT /* Default function. */
#define EXPORT FAR _loadds /* Export function. */
char szDTClassName[] = "DisplayTopic"; /* Extended Window class name */
char szDTTitle[] = "Topic Information"; /* Extended Window Title */
BOOL fDisplayDT = FALSE;
HWND hwndDT = NULL;
LONG lOffsetDT;
HANDLE ghModule;
long EXPORT PASCAL DisplayTopicProc (HWND hwnd,
UINT wMsg,
WPARAM wParam,
LPARAM lParam);
LPFN_HFSOPENSZ lpfn_HfsOpenSz;
LPFN_RCCLOSEHFS lpfn_RcCloseHfs;
LPFN_RCLLINFOFROMHF lpfn_RcLLInfoFromHf;
LPFN_FACCESSHFS lpfn_FAccessHfs;
LPFN_HFOPENHFS lpfn_HfOpenHfs;
LPFN_LCBREADHF lpfn_LcbReadHf;
LPFN_RCCLOSEHF lpfn_RcCloseHf;
/***************************************************************************
*
- Name HelloWorld
-
* Purpose The most trivial of DLL functions.
*
***************************************************************************/
PUBLIC BOOL PASCAL EXPORT HelloWorld( LONG hwndContext, LPSTR lszHlpFile )
{
MessageBeep(0);
return TRUE;
}
/***************************************************************************
*
- Name FInitExtendedWindow
-
* Purpose Called by LibMain during initialization of DLL.
*
* Arguments hModule Module handle for the library
*
* Returns
*
* +++
*
* Notes
*
***************************************************************************/
BOOL FInitExtendedWindow( HANDLE hModule )
{
WNDCLASS wc;
ghModule = hModule;
wc.lpszClassName = szDTClassName;
wc.style = CS_GLOBALCLASS;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = NULL;
wc.lpszMenuName = NULL;
wc.hbrBackground = COLOR_WINDOW + 1;
wc.hInstance = hModule;
wc.lpfnWndProc = DisplayTopicProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if (!RegisterClass (&wc))
return FALSE; /* Initialization failed */
return TRUE; /* if we got here everything is ok! */
}
/***************************************************************************
*
- Name DisplayTopicInfo
-
* Purpose This DLL function shows the Display Topic extended
* window.
*
* Arguments handle to the main Help window
*
***************************************************************************/
PUBLIC void PASCAL EXPORT DisplayTopicInfo(
LONG hwndParent)
{
if (hwndDT == NULL)
{
hwndDT = CreateWindow( szDTClassName,
szDTTitle,
WS_CAPTION | WS_POPUPWINDOW,
100, 100, 400, 100,
(WORD)hwndParent, NULL,
ghModule,
0L );
}
fDisplayDT = TRUE;
ShowWindow( hwndDT, SW_SHOW );
}
/***************************************************************************
*
- Name DisplayTopicProc
-
* Purpose Displays topic information
*
* Arguments hwnd This window's handle
* wMsg The current message
* wParam Message dependent
* lParam Message dependent
*
* Returns Message dependent
*
* +++
*
* Notes
* This only displays the current topic offset number. Ordinarily,
* you would have to look this number up in a table to give
* more meaningful information.
*
***************************************************************************/
long EXPORT PASCAL DisplayTopicProc( HWND hwnd,
UINT wMsg,
WPARAM wParam,
LPARAM lParam )
{
PAINTSTRUCT ps;
TEXTMETRIC tm;
char rgchBuf[30];
switch (wMsg)
{
case WM_CREATE:
return 0L;
case WM_PAINT:
BeginPaint( hwnd, &ps );
GetTextMetrics( ps.hdc, &tm );
SetTextColor( ps.hdc, GetSysColor( COLOR_WINDOWTEXT ) );
SetBkColor( ps.hdc, GetSysColor( COLOR_WINDOW ) );
wsprintf( rgchBuf, "Topic Offset: %ld", lOffsetDT );
TextOut( ps.hdc, tm.tmMaxCharWidth/2,
(tm.tmHeight + tm.tmExternalLeading)/2,
rgchBuf, lstrlen(rgchBuf) );
EndPaint( hwnd, &ps );
return 0L;
case WM_CLOSE:
fDisplayDT = FALSE;
hwndDT = NULL;
break;
}
return DefWindowProc (hwnd, wMsg, wParam, lParam);
}
/***************************************************************************
*
- Name ExportBag
-
* Purpose Copies a Baggage file to a DOS file.
*
* Arguments lszHLPname: Name of Help file
* lszBagFName: Name of internal Baggage file
* lszExportName: Name of DOS file to copy to
* qError: Help error structure
*
* Returns TRUE if successful, FALSE otherwise.
*
***************************************************************************/
#define wCOPY_SIZE (WORD)32768
PUBLIC BOOL PASCAL EXPORT ExportBag(
LPSTR lszHLPname,
LPSTR lszBagFName,
LPSTR lszExportName,
QME qError)
{
HANDLE hfsHlp; // handle to .HLP file
HANDLE hfBag; // file handle to bag file
HANDLE hFile; // handle to output file
BOOL fClean = TRUE; // if set, Delete file in Error state Machine.
DWORD dwBytesRead; // input bytes read
HANDLE hMem; // handle to copy buffer
LPBYTE lpMem; // ptr to copy buffer
OFSTRUCT ofs;
hfsHlp = hfBag = hMem = NULL;
hFile = (HANDLE)-1;
if ((hfsHlp = (*lpfn_HfsOpenSz)(lszHLPname, fFSOpenReadOnly)) == NULL)
{
qError->fwFlags = fwMERR_ABORT;
qError->wError = wMERR_PARAM;
goto ExitBag;
}
if (((*lpfn_FAccessHfs)(hfsHlp, lszBagFName, NULL)) == FALSE)
{
qError->fwFlags = fwMERR_RETRY;
qError->wError = wMERR_MESSAGE;
lstrcpy(qError->rgchError, "Could not open baggage file `");
lstrcat(qError->rgchError, lszBagFName);
lstrcat(qError->rgchError, "'.");
goto ExitBag;
}
if ((hfBag = (*lpfn_HfOpenHfs)(hfsHlp, lszBagFName, fFSOpenReadOnly))
== NULL)
{
qError->fwFlags = fwMERR_ABORT;
qError->wError = wMERR_ERROR;
goto ExitBag;
}
if ((hMem = GlobalAlloc(GMEM_MOVEABLE,
(DWORD)wCOPY_SIZE)) == NULL)
{
qError->fwFlags = fwMERR_ABORT;
qError->wError = wMERR_MEMORY;
goto ExitBag;
}
lpMem = GlobalLock(hMem);
OpenFile(lszExportName, &ofs, OF_DELETE);
if ((hFile = _lcreat(lszExportName,0)) == -1)
{
qError->fwFlags = fwMERR_ABORT;
qError->wError = wMERR_ERROR;
goto ExitBag;
}
do {
if ((dwBytesRead =
(*lpfn_LcbReadHf)(hfBag, lpMem, wCOPY_SIZE)) == -1L)
{
qError->fwFlags = fwMERR_ABORT;
qError->wError = wMERR_ERROR;
goto ExitBag;
}
if (_lwrite(hFile, lpMem,(WORD) dwBytesRead) != (WORD) dwBytesRead)
{
qError->fwFlags = fwMERR_ABORT | fwMERR_RETRY;
qError->wError = wMERR_MESSAGE;
lstrcpy(qError->rgchError, "Out of disk space.");
goto ExitBag;
}
} while (dwBytesRead == wCOPY_SIZE);
ExitBag:
if (hfBag != NULL)
(*lpfn_RcCloseHf)(hfBag);
if (hfsHlp != NULL)
(*lpfn_RcCloseHfs)(hfsHlp);
if (hMem != NULL)
{
GlobalUnlock(hMem);
GlobalFree(hMem);
}
if (hFile != -1)
_lclose(hFile);
if (qError->wError != wMERR_NONE && fClean)
OpenFile(lszExportName, &ofs, OF_DELETE);
return (qError->wError == wMERR_NONE);
}
PUBLIC BOOL PASCAL GetCallBacks(
VPTR VPtr,
LONG lVersion)
{
// hfs level:
lpfn_HfsOpenSz = (LPFN_HFSOPENSZ) VPtr[HE_HfsOpenSz];
lpfn_RcCloseHfs = (LPFN_RCCLOSEHFS) VPtr[HE_RcCloseHfs];
// bag level routines
lpfn_FAccessHfs = (LPFN_FACCESSHFS) VPtr[HE_FAccessHfs];
lpfn_HfOpenHfs = (LPFN_HFOPENHFS) VPtr[HE_HfOpenHfs];
lpfn_LcbReadHf = (LPFN_LCBREADHF) VPtr[HE_LcbReadHf];
lpfn_RcCloseHf = (LPFN_RCCLOSEHF) VPtr[HE_RcCloseHf];
lpfn_RcLLInfoFromHf = (LPFN_RCLLINFOFROMHF) VPtr[HE_RcLLInfoFromHf];
return TRUE;
}
PUBLIC LONG PASCAL EXPORT LDLLHandler(
WORD wMsg,
LONG lParam1,
LONG lParam2)
{
switch(wMsg)
{
case DW_WHATMSG:
return DC_INITTERM | DC_CALLBACKS | DC_MINMAX | DC_JUMP;
case DW_CALLBACKS:
GetCallBacks((VPTR)lParam1,lParam2);
return TRUE;
case DW_MINMAX:
if ( fDisplayDT )
ShowWindow( hwndDT, (lParam1 == 1L ? SW_HIDE : SW_SHOW) );
return TRUE;
case DW_ENDJUMP:
lOffsetDT = lParam1;
InvalidateRect( hwndDT, NULL, TRUE );
return TRUE;
case DW_CHGFILE:
case DW_TERM:
ShowWindow( hwndDT, SW_HIDE );
fDisplayDT = FALSE;
return TRUE;
case DW_INIT:
return TRUE;
}
return FALSE;
}